$((function() {
	//			var pd=false;
	$(".removeshop").click(function() { 
		$(this.parentNode).remove();
		count();
	}).mouseover(function() {
		$(this).css("cursor", "pointer");
	});
	$(".quanxuan").click(function() {
		if(this.checked) {
			$("#gouwuche input[type='checkbox']").attr("checked", "checked");
			$(".quanxuan").attr("checked", "checked");
		} else {
			$("#gouwuche input[type='checkbox']").removeAttr("checked");
			$(".quanxuan").removeAttr("checked");
		}
		count();
	});
	$("#gouwuche input[type='checkbox']").click(function() {
		if(this.checked) {
			$(this).attr("checked", "checked");
		} else {
			$(this).removeAttr("checked");
		}
		count();
	});

	function count() {
		var checked = $("#gouwuche input[checked='checked']");
		//console.log(checked.length);
		$(".shop_bott p span:nth-child(1)").html(checked.length);
		if(checked.length > 0) {
			//var div = $("#gouwuche div");
			var price = 0;
			for(var i = 0; i < checked.length; i++) {
				price += parseFloat(checked[i].parentNode.parentNode.children[4].innerHTML);
			}
			price = price.toString();
			var star = price.indexOf(".");
			var xiaoshu;
			if(star != -1) {
				xiaoshu = price.substr(star + 1, 2);
				if(xiaoshu.length == 1) {
					xiaoshu = xiaoshu + "0";
				}
			} else {
				xiaoshu = "00";
			}
			price = parseInt(price)
			var newprice = price + "." + xiaoshu;
			$(".shop_bott p span:nth-child(2)").html(newprice);
		} else {
			$(".shop_bott p span:nth-child(2)").html("0.00");
		}
	}
	count();

	function jisuan(t, n) { 
		var jisuan = parseFloat(t.parentNode.parentNode.children[2].innerHTML);
		jisuan *= n;
		jisuan = jisuan.toString();
		var star = jisuan.indexOf(".");
		if(star != -1) {
			xiaoshu = jisuan.substr(star + 1, 2);
			if(xiaoshu.length == 1) {
				xiaoshu = xiaoshu + "0";
			}
		} else {
			xiaoshu = "00";
		}
		jisuan = parseInt(jisuan)
		$(t.parentNode).next().html(jisuan + "." + xiaoshu);
	}
	//鏁伴噺鍑�
	$("#gouwuche .shop_nav i.del").click(function() {
		var $num = parseInt($(this).next().val());
		if(!isNaN($num)) {
			if($num == 1) {
				this.parentNode.children[3].innerHTML = "请至少选择一件";
				this.parentNode.children[3].style.display = "block";
				return;
			}
			$num--;
			$(this).next().val($num);
			this.parentNode.children[3].style.display = "none";
			jisuan(this, $num);
		} else {
			this.parentNode.children[3].innerHTML = " ";
			this.parentNode.children[3].style.display = "block";
			$(this).next().val("1");
			jisuan(this, 1);
		}
		count();
	});
	$("#gouwuche .shop_nav i.add").click(function() {
		var $num = parseInt(this.parentNode.children[1].value);
		//				console.log($num)
		if(!isNaN($num)) {
			if($num >= 1) {
				$num++;
				this.parentNode.children[1].value = $num;
				this.parentNode.children[3].style.display = "none";
				jisuan(this, $num);
			}
		} else {
			this.parentNode.children[3].innerHTML = " ";
			this.parentNode.children[3].style.display = "block";
			this.parentNode.children[1].value = "1";
			jisuan(this, 1);
		}
		count();
	});
})());